"""Definition of the agent content type
"""

from zope.interface import implements

from Products.Archetypes import atapi
from Products.ATContentTypes.content import folder
from Products.ATContentTypes.content import schemata

# -*- Message Factory Imported Here -*-
from my315ok.xtinfocontent import xtinfocontentMessageFactory as _

from my315ok.xtinfocontent.interfaces import Iagent
from my315ok.xtinfocontent.config import PROJECTNAME

agentSchema = folder.ATFolderSchema.copy() + atapi.Schema((

    # -*- Your Archetypes field definitions here ... -*-

    atapi.StringField(
        'name',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"agent name"),
            description=_(u""),
        ),
    ),
    atapi.StringField(
        'phone',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"phone number"),
            description=_(u""),
        ),
        required=True,
    ),
    
    atapi.IntegerField(
        'qq',
        storage=atapi.AnnotationStorage(),
        widget=atapi.IntegerWidget(
            label=_(u"QQ number"),
            description=_(u""),
        ),
        validators=('isInt'),
    ),


    atapi.StringField(
        'addr',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"agent address"),
            description=_(u""),
        ),
    ),
    atapi.StringField(
        'group',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"agent group"),
            description=_(u""),
        ),
    ),

    atapi.TextField(
        'text',
        storage=atapi.AnnotationStorage(),
        default_output_type = 'text/html',
        widget=atapi.RichWidget(
            label=_(u"agent description"),
            description=_(u""),
        ),
    ),  


    atapi.StringField(
        'blog',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"blog url"),
            description=_(u""),
        ),
    ),
))

# Set storage on fields copied from ATFolderSchema, making sure
# they work well with the python bridge properties.

agentSchema['title'].storage = atapi.AnnotationStorage()
agentSchema['description'].storage = atapi.AnnotationStorage()

schemata.finalizeATCTSchema(
    agentSchema,
    folderish=True,
    moveDiscussion=False
)


class agent(folder.ATFolder):
    """medium agent information"""
    implements(Iagent)

    meta_type = "agent"
    schema = agentSchema
    _at_rename_after_creation = True

    title = atapi.ATFieldProperty('title')
    description = atapi.ATFieldProperty('description')

    # -*- Your ATSchema to Python Property Bridges Here ... -*-
    qq = atapi.ATFieldProperty('qq')

    addr = atapi.ATFieldProperty('addr')

    text = atapi.ATFieldProperty('text')

    group = atapi.ATFieldProperty('group')

    blog = atapi.ATFieldProperty('blog')

    phone = atapi.ATFieldProperty('phone')

    name = atapi.ATFieldProperty('name')

    text = atapi.ATFieldProperty('text')



atapi.registerType(agent, PROJECTNAME)
